using System;
using System.Collections.Generic;
using System.Threading;
using GZ.DB.Entity.wcs_yb;

namespace GZ.Projects.WCS_YB
{
	/// <summary>
	/// 堆垛机发送任务到Redis
	/// </summary>
	public class StackerSendToRedis
	{

		public bool SendTask_SingleStation(StackerTaskEntity task, out string err)
		{
			err = "";
			try
			{
				string groupName = $"TC01.SendTask";
				string setQueue = $"TC01Queue";
				string contType = $"TC01.wcs_trayType";
				string srcZ = $"TC01.wcs_startPosX";
				string srcX = $"TC01.wcs_startPosY";
				string srcY = $"TC01.wcs_startPosZ";
				string destZ = $"TC01.wcs_endPosX";
				string destX = $"TC01.wcs_endPosY";
				string destY = $"TC01.wcs_endPosZ";
				string taskType = $"TC01.wcs_taskType";
				string taskNo = $"TC01.wcs_taskNo";
				string taskExe = $"TC01.wcs_taskExe";  //1下发 2数据异常

				GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity
				{
					groupName = groupName,
					queueStatus = 1,
					queueTime = DateTime.Now,
					writeList = new List<GZ.Modular.Redis.ParamData>
					{
						new GZ.Modular.Redis.ParamData { paramName = contType, paramValue = task.TrayType },
						new GZ.Modular.Redis.ParamData { paramName = srcZ, paramValue = task.FromX.ToString() }, //排
						new GZ.Modular.Redis.ParamData { paramName = srcX, paramValue = task.FromY.ToString() }, //列
						new GZ.Modular.Redis.ParamData { paramName = srcY, paramValue = task.FromZ.ToString() }, //层
						new GZ.Modular.Redis.ParamData { paramName = destZ, paramValue = task.ToX.ToString() },
						new GZ.Modular.Redis.ParamData { paramName = destX, paramValue = task.ToY.ToString() },
						new GZ.Modular.Redis.ParamData { paramName = destY, paramValue = task.ToZ.ToString() },
						new GZ.Modular.Redis.ParamData { paramName = taskType, paramValue = task.DeviceTaskType },
						new GZ.Modular.Redis.ParamData { paramName = taskNo, paramValue = task.DeviceTaskNo },
						new GZ.Modular.Redis.ParamData { paramName = taskExe, paramValue = "1" }

					}
				};
				return Conn.YBRedis.SetQueue(group, setQueue, "", "");
			}
			catch (Exception ex)
			{
				err += ex.ToString();
				return false;
			}
		}
		
		public bool ClearTask_SingleStation(StackerTaskEntity task, out string err)
		{
			
			err = "";
			try
			{
				string groupName = $"TC01.SendTask";
				string setQueue = $"TC01Queue";
				string contType = $"TC01.wcs_trayType";
				string srcZ = $"TC01.wcs_startPosX";
				string srcX = $"TC01.wcs_startPosY";
				string srcY = $"TC01.wcs_startPosZ";
				string destZ = $"TC01.wcs_endPosX";
				string destX = $"TC01.wcs_endPosY";
				string destY = $"TC01.wcs_endPosZ";
				string taskType = $"TC01.wcs_taskType";
				string taskNo = $"TC01.wcs_taskNo";
				string taskExe = $"TC01.wcs_taskExe";  //1下发 2数据异常

				GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity
				{
					groupName = groupName,
					queueStatus = 1,
					queueTime = DateTime.Now,
					writeList = new List<GZ.Modular.Redis.ParamData>
					{
						new GZ.Modular.Redis.ParamData { paramName = contType, paramValue = "0" },
						new GZ.Modular.Redis.ParamData { paramName = srcZ, paramValue = "0" }, //排
						new GZ.Modular.Redis.ParamData { paramName = srcX, paramValue = "0" }, //列
						new GZ.Modular.Redis.ParamData { paramName = srcY, paramValue = "0" }, //层
						new GZ.Modular.Redis.ParamData { paramName = destZ, paramValue = "0" },
						new GZ.Modular.Redis.ParamData { paramName = destX, paramValue = "0" },
						new GZ.Modular.Redis.ParamData { paramName = destY, paramValue = "0" },
						new GZ.Modular.Redis.ParamData { paramName = taskType, paramValue = "0" },
						new GZ.Modular.Redis.ParamData { paramName = taskNo, paramValue = "0" },
						new GZ.Modular.Redis.ParamData { paramName = taskExe, paramValue = "0" }

					}
				};
				return Conn.YBRedis.SetQueue(group, setQueue, "", "");
			}
			catch (Exception ex)
			{
				err += ex.ToString();
				return false;
			}

		}
		
		public bool ConfirmTask_SingleStation(string confirmValue, out string err)
		{
			
			err = "";
			try
			{
				string groupName = $"TC01.StackerFinishSend";
				string setQueue = $"TC01Queue";
				string wcsTaskFinishAffirm = $"TC01.wcs_taskFinishAffirm";  //1下发 2数据异常

				GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity
				{
					groupName = groupName,
					queueStatus = 1,
					queueTime = DateTime.Now,
					writeList = new List<GZ.Modular.Redis.ParamData>
					{
						new GZ.Modular.Redis.ParamData { paramName = wcsTaskFinishAffirm, paramValue = confirmValue }
					}
				};
				return Conn.YBRedis.SetQueue(group, setQueue, "", "");
			}
			catch (Exception ex)
			{
				err += ex.ToString();
				return false;
			}

		}
	}
}